import qrcode
from PIL import Image
from pyzbar.pyzbar import decode


def Generate_qrcode(data):
    qr = qrcode.QRCode(
        version=1,
        error_correction=qrcode.constants.ERROR_CORRECT_L,
        box_size=10,
        border=4)
    qr.add_data(data)
    qr.make(fit=True)
    img = qr.make_image(fill_color="black", back_color="white")
    print(img.width, img.height)
    img.save('qrcode.png')


def Decode_qrcode(filename):
    result = decode(Image.open(filename))
    print("Data：", result[0][0].decode())


if __name__ == '__main__':
    Generate_qrcode('Python')
    #Decode_qrcode('qrcode.png')
